﻿using System;
using System.Linq;
using Landpy.CruiseControlNet.FacadeInterface.ConfigurationModule;
using Landpy.CruiseControlNet.FacadeInterface.RepositoryModule;
using Landpy.CruiseControlNet.Infrastructure.Aop.WrapAttribute;

namespace Landpy.CruiseControlNet.DomainLayer.RepositoryModule
{
    public class TriggerRepository : ITriggerRepository
    {
        private IProjectRepository ProjectRepository { get; set; }

        public TriggerRepository()
        {
            this.ProjectRepository = new ProjectRepository();
        }

        [NotThrowException]
        [ExceptionMessageBox]
        [LogException]
        public Trigger GetTriggerById(CruiseControl cruiseControl, Guid projectId, Guid id)
        {
            var queryProject = this.ProjectRepository.GetProjectById(cruiseControl, projectId);
            return (from Trigger trigger in queryProject.Triggers
                    where trigger.Id == id
                    select trigger).FirstOrDefault();
        }
    }
}